import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/**
 * @author zhangdi
 * @version 1.0
 * @date 2022.3.15 11:12
 */
public class RDemo3 {
    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            int finalI = i;
            Thread t0 = new Thread(new Runnable() {
                int num = 0;
                @Override
                public void run() {
                    while (ReentrantLockDemo.getInst() != null) {
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        ++num;
                        if (num == 200) {
                            ReentrantLockDemo.getInst().request(finalI);
                            num = 0;
                        }
                    }
                }
            });
            t0.start();
        }

//        ThreadFactory threadFactory = new ThreadFactory() {
//            @Override
//            public Thread newThread(Runnable r) {
//                Thread thread = new Thread(null, r, "t1", 5);
//                thread.setDaemon(false);
//                return thread;
//            }
//        };
//        ScheduledExecutorService service = Executors.newScheduledThreadPool(2, threadFactory);
//        service.scheduleWithFixedDelay(new ReentrantLockDemo.timer0(), 2, 2, TimeUnit.SECONDS);


//        Thread t1 = new Thread(new Runnable() {
//            final String s1 = "timer";
//            @Override
//            public void run() {
//                while (ReentrantLockDemo.getInst() != null) {
//                    try {
//                        Thread.sleep(10);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                    if (ReentrantLockDemo.getInst().state.get() != 1) {
//                        ReentrantLockDemo.getInst().data.set(0);
//                        ReentrantLockDemo.getInst().send(s1);
//                    }
//                }
//            }
//        });
//        t1.start();
    }
}
